const express = require('express')

const router = express.Router()
const db = require("../mysql/db")
router.get('/', (req, res, next) => {
    res.send("你好")
    next()
})

//玄幻页面请求数据
router.get('/index', (req, res) => {
    const sql = "SELECT * FROM storage where sort='东方玄幻'"
    db.query(sql, (err, result) => {
        if (err) return console.log(err.message)
        const storagedData = JSON.stringify(result)
        res.send(storagedData)
    })
})

//搜索模糊查询功能
router.post("/selectAll", (req, res) => {
    // const sql = "SELECT * FROM storage WHERE author LIKE ?";
    const sql = "SELECT * FROM storage WHERE title LIKE ? OR author LIKE ?"
    db.query(sql, [`%${req.body.info}%`, `%${req.body.info}%`], (err, result) => {
        if (err) return console.log(err.message)
        const data = JSON.stringify(result)
        res.send(data)
    })
})

module.exports = router